<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/06/02
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * 评论管理
 * @package app\erp\model
 */
class ErpEvaluate extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_goods_evaluate';
    protected $table_img = 'xm_erp_goods_evaluate_img';

    /**
     * 添加数据
     * @param goods_id 	            int     商品id
     * @param score 		        float   评分
     * @param content 		        string  内容
     * @param uid 		            int     评论人id
     * @param create_time 		    string  创建时间
     * @param update_time 		    string  编辑时间
     * @author dou<51779987@qq.com>
     * @return array_out(code, message, (int)id)
     */
    public function addData($goods_id, $score, $content, $uid, $order_id, $spbz_score, $qifw_score, $sku_id){
        $data['goods_id']            = $goods_id;
        $data['score']               = $score;
        $data['content']             = $content;
        $data['uid']                 = $uid;
        $data['spbz_score']          = $spbz_score;
        $data['qifw_score']          = $qifw_score;
        $data['order_id']            = $order_id;
        $data['sku_id']              = $sku_id;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();

        if($res){
            return array_out(200, 'success',$this->id);
        }else{
            return array_out(-1001, 'error');
        }
    }

	/**
     * 编辑数据
     * @param id 	                int     评论id
     * @param goods_id 	            int     商品id
     * @param score 		        float   评分
     * @param content 		        string  内容
     * @param uid 		            int     评论人id
     * @param create_time 		    string  创建时间
     * @param update_time 		    string  编辑时间
     * @author dou<51779987@qq.com>
     * @return array_out(code, message, (int)id)
     */
	public function editData($id,$goods_id, $score, $content, $uid, $spbz_score, $qifw_score, $sku_id){
		$map = [];
		$map['id'] = $id;
		
		$data = [];
        $data['goods_id']            = $goods_id;
        $data['score']               = $score;
        $data['content']             = $content;
        //$data['uid']                 = $uid;
		$data['spbz_score']          = $spbz_score;
        $data['qifw_score']          = $qifw_score;
        $data['sku_id']              = $sku_id;

        $res = $this ->update($data, $map);
		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 删除数据
     * @param int $id
     * @author dou<51779987@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
